﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Db4objects.Db4o;
using Mapenect.GesturePatterns;
namespace Mapenect.Database
{
    internal class DatabaseController : IDatabase
    {
        private IObjectContainer db;
        public bool Connect()
        {
            try
            {
                db = Db4oFactory.OpenFile("gestures.db4o");
                return true;
            }
            catch
            {
                return false;
            }
        }

        public DatabaseController Disconnect()
        {
            if (db != null)
            {
                db.Close();
                db = null;
            }
            return null;
        }

        public void StoreGesture(GesturePatterns.Gesture gest)
        {
            db.Store(gest);
        }

        public List<Gesture> ReadGestures()
        {
            List<Gesture> ret = new List<Gesture>();
            ret = db.Query<Gesture>(typeof(Gesture)).ToList<Gesture>();
            return ret;
        }
    }
}
